package com.bdqn.desiremall.serivce.order;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.bdqn.desiremall.entity.Mall_Order;
import com.bdqn.desiremall.mapper.Mall_OrderMapper;
import com.desiremall.util.MyBatisUtil;

public class OrderSerivceImpl implements  OrderSerivce{
	SqlSession session =null;
	List<Mall_Order> orderList=null;
	@Override
	public List<Mall_Order> orderView(Mall_Order order) {
		try {
			
			session=MyBatisUtil.getSession();
			
			Mall_OrderMapper orderMapper=session.getMapper(Mall_OrderMapper.class);
			orderList= orderMapper.findOrder(order);
			return orderList;
			}catch (Exception e) 
	{
		//session.rollback();
		e.printStackTrace();
	}
	finally
	{
		MyBatisUtil.closeSqlSession(session);
	}
		return orderList;
	}

	@Override
	public boolean cancelTheOrder(int orderId) {
		int i=0;
		try {
				//1����ȡsqlSession����
				session=MyBatisUtil.getSession();
				//2����ȡUserMapperʵ��
				Mall_OrderMapper orderMapper=session.getMapper(Mall_OrderMapper.class);
				i= orderMapper.removeOrder(orderId);
				if(0<i)
				{
				session.commit();
				return true;
				}
				
			}catch (Exception e) 
		{
			session.rollback();
			e.printStackTrace();
		}
			
	finally{
			MyBatisUtil.closeSqlSession(session);
			}
			return false;
	}

	@Override
	public boolean addOrder(Mall_Order order) {
		int i=0;
	try {
			//1����ȡsqlSession����
			session=MyBatisUtil.getSession();
			//2����ȡUserMapperʵ��
			Mall_OrderMapper orderMapper=session.getMapper(Mall_OrderMapper.class);
			i= orderMapper.addOrder(order);
			if(0<i)
			{
			session.commit();
			return true;
			}
			
		}catch (Exception e) 
	{
		session.rollback();
		e.printStackTrace();
	}
		
finally{
		MyBatisUtil.closeSqlSession(session);
		}
		return false;
	}

	@Override
	public boolean changeOrder(Mall_Order order) {
		// TODO Auto-generated method stub
		return false;
	}


}
